import { Button, Text, View } from 'react-native';
import { useState } from 'react';
import { addBookAPI, getBooksAPI, IBook } from './src/services/bookService';

export default function App() {
  const [book, setbook] = useState<IBook[]>([]);

  const getBook = async () => {
    const res = await getBooksAPI();
    console.log(res);
    setbook(res);
  };
  const addBook = async () => {
    const res = await addBookAPI(
      {
        bookname: "123",
        author: "123",
        publisher: '123',
      }
    );
    console.log(res);
  };

  return (
    <View>
      <Button title="获取图书" onPress={getBook} />
      <Button title="新增图书"  onPress={addBook}/>
      <View>
        {book.map(v => (
          <Text key={v.id}>{v.bookname} - {v.publisher}</Text>
        ))}
      </View>
    </View>

  );
}


